#include <iostream>
#include <vector>
#include <ctime>
#include <algorithm>


// 格式化打印彩票
void print_cp(std::vector<int> cp) 
{
    std::cout.width(2);
    for (std::vector<int>::iterator it = cp.begin(); it < cp.end(); it++) {
        if(it - cp.begin() == cp.size() - 1) {
            std::cout << " | " << *it ;
        }
        else {
            std::cout << " " << *it;
        }
    }
    std::cout << std::endl;
}


std::vector<int> get_one_cp() {
    std::vector<int> one_cp;
    std::vector<int> red_pool;
    std::vector<int> blue_pool;
    //初始化待选红球数组和待选蓝球数组
    for (int i = 0; i < 33; i++) {
        if (i < 16) {
            blue_pool.push_back(i+1);
        }
        red_pool.push_back(i+1);
    }
    // 产生6个红球
    for (int i = 0; i < 6; i++) {
        int index = rand() % red_pool.size();   // 随机选取红球数组下标
        one_cp.push_back(red_pool.at(index));   // 插入选出的红球到结果数组
        red_pool.erase(red_pool.begin() + index); //从待选红球数组中删除选中红球
    }
    // 对产生的6个红球做升序排序
    std::sort(one_cp.begin(), one_cp.end());
    // 产生一个篮球
    int index = rand() % blue_pool.size();
    one_cp.push_back(blue_pool.at(index));
    blue_pool.erase(blue_pool.begin() + index);
    return one_cp;
}

int main(int argc, char* argv[]) 
{
    std::cout << "This is caipiao system!!!" << std::endl;
    srand(time(0));
    for (int i = 0; i < 6; i++) {
        std::vector<int> cp_one = get_one_cp();
        print_cp(cp_one);
    }
    return 0;
}